﻿using System;
using System.Windows.Forms;
using HoldemHook;
using System.Drawing.Win32;
using HoldemGame;

namespace HoldemView
{
    public class ConnectionDirector
    {
        bool _connected = false;
        private FTChatParser MessageProxy;
        public bool Connected { get { return _connected; } }
        public IGame Game;

        public ConnectionDirector(IGame game)
        {
            Game = game;

        }

        public void Connect()
        {
            try
            {
                _connected = false;
                ConnectFT();
                _connected = true;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }

        void ConnectFT()
        {
            FTDriver.DriverEvent += new EventHandler<DriverEventArgs>(FTDriver_DriverEvent);
            FTDriver.Start();
        }

        void FTDriver_DriverEvent(object sender, DriverEventArgs e)
        {
            if (e.Kind == DriverEventArgs.EventKind.TableConnected)
            {
                MessageProxy = new FTChatParser(e.Window as ITextOutEventSource, Game);
                //new FTTableParser(e.Window as ITextOutEventSource, Game);
            }
        }

    }
}